package com.bw.live_streaming.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.live_streaming.dao.SlideshowDao;
import com.bw.live_streaming.vo.SinatvVo;
import com.bw.live_streaming.vo.SinatvVowj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.common.utils.PageUtils;
import com.bw.common.utils.Query;

import com.bw.live_streaming.dao.SinatvDao;
import com.bw.live_streaming.entity.SinatvEntity;
import com.bw.live_streaming.service.SinatvService;


@Service("sinatvService")
public class SinatvServiceImpl extends ServiceImpl<SinatvDao, SinatvEntity> implements SinatvService {

    @Autowired
    private SlideshowDao slideshowDao;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SinatvEntity> page = this.page(
                new Query<SinatvEntity>().getPage(params),
                new QueryWrapper<SinatvEntity>()
        );

        return new PageUtils(page);
    }
    @Override
    public IPage<SinatvVowj> getList(Integer page, Integer limit, Integer slideshowId) {
        //根据前台传过来的slideshowId 给对应的点击量+1
        slideshowDao.upd(slideshowId,1);
        //redis同步
        redisTemplate.delete("live_streaming-Slideshow");

        Page<SinatvVowj> sinatvVoPage = new Page<>(page, limit);
        return baseMapper.getList(sinatvVoPage);
    }


    @Override
    public List<SinatvVo> lists(Integer docterId) {
        return baseMapper.lists(docterId);
    }

}